<?php
class Control_DataAnalysis_activityStatistics {

	function activityStatistics() {
		$nowGame = 	$game 	= 	MooForm::request('game');
		$activityId 		= 	MooForm::request('activityId');
		$game = MooObj::get('Game')->transportGame($game);
		$nowChannel = $channel = MooObj::get('Game')->transportChannel($game, $channel);
		$action 		= 	MooForm::request('action');
		// 设置活动信息
		if($action == 0) {
			MooView::render('activityStatistics');
		} else if($action == 1) {
			MooObj::get('Control_Data')->setPlatformData($game);
			$activityEffectConf = MooConfig::get('activityeffect.' . $game);
			$activitys = array();
			if($activityEffectConf) {
				foreach ($activityEffectConf as $key => $val) {
					$activity['id'] = $key;
					$activity['name'] = $val;
					$activitys[] = $activity;
				}
			}
			
			$fetch_activity = MooConfig::get('main.dataAnalysis.fetch_activity_statistics');
			$url = $fetch_activity . "?game=" . $game . "&activityid=" . $activityId;
			$data = MooUtil::curl_send($url);

		//	$data = '[{"activityid":"1","activityno":"2","puidcount":"5","goldconsume":"1100"},{"activityid":"2","activityno":"2","puidcount":"5","goldconsume":"1200"}]';
			$activityEffectConf = MooConfig::get('activityeffect.' . $game);
			if($data) {
				$dataArr = MooJson::decode($data, true);
				$viewData = array();
				foreach ($dataArr as $key => $val) {
					$aId = $val['activityid'];	
					$view[0] = $activityEffectConf[$aId] ? $activityEffectConf[$aId] : $aId;
					$view[1] = $val['goldconsume'];
					$viewData[] = $view;
				}
				
				foreach ($dataArr as $key => $val) {
					$aId = $val['activityid'];
					$dataArr[$key]['activityname'] = $activityEffectConf[$aId] ? $activityEffectConf[$aId] : $aId;
					$dataArr[$key]['accgoldconsume'] = sprintf("%.1f", $val['goldconsume'] / $val['puidcount']); 
				}
				MooView::set('dataArr', $dataArr);
			}
			
			$viewData = MooJson::encode($viewData);
			// 格式化数据
			$viewData = str_replace(',"',',',$viewData);
			$viewData = str_replace('"]',']',$viewData);

			MooView::set('activitys', $activitys);
			MooView::set('nowGame', $nowGame);
			MooView::set('action', $action);
			MooView::set('nowActivityId', $activityId);
			
			MooView::set('viewData', $viewData);
			MooView::set('goldSource', $dataArr);
			MooView::render('activityStatistics');
		} else {
			exit("error!");
		}
	}
}